package jvm;

/**
 * Created by duan lian on 2017-08-04.
 */
public class DeadLockAndIntegerCache implements Runnable{
	int a,b;

	public DeadLockAndIntegerCache(int a, int b) {
		this.a = a;
		this.b = b;
	}

	@Override
	public void run() {
		synchronized (Integer.valueOf(a)){
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			synchronized (Integer.valueOf(b)){
				System.out.println(a + b);
			}
		}
	}

	public static void main(String[] args) {
		new Thread(new DeadLockAndIntegerCache(1,2)).start();
		new Thread(new DeadLockAndIntegerCache(2,1)).start();
	}
}
